package com.ts.threatre.controller;

import com.ts.common.page.PageData;
import com.ts.common.utils.Result;
import com.ts.common.validator.AssertUtils;
import com.ts.common.validator.ValidatorUtils;
import com.ts.common.validator.group.AddGroup;
import com.ts.common.validator.group.DefaultGroup;
import com.ts.common.validator.group.UpdateGroup;
import com.ts.threatre.dto.ThreatreDTO;
import com.ts.threatre.service.ThreatreService;
import com.ts.threatre.vo.ThreatreVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author ywl 193363874@qq.com
 * @since 1.0.0 2023-07-18
 */
@RestController
@RequestMapping("/threatre")
@Slf4j
public class ThreatreController {
    @Autowired
    private ThreatreService threatreService;

    @GetMapping("/page")
    public Result<PageData<ThreatreDTO>> page(@RequestParam Map<String, Object> params){
        PageData<ThreatreDTO> page = threatreService.page(params);

        return new Result<PageData<ThreatreDTO>>().ok(page);
    }

    @GetMapping("/{id}")
    public Result<ThreatreDTO> get(@PathVariable("id") Long id){
        ThreatreDTO data = threatreService.get(id);

        return new Result<ThreatreDTO>().ok(data);
    }

    @PostMapping
    public Result save(@RequestBody ThreatreDTO dto){
        //效验数据
        ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);

        threatreService.save(dto);

        return new Result();
    }
    @PostMapping("/list")
    public Result list(@RequestBody Map<String,Object> dto){
        log.debug(dto.toString());
        List<ThreatreVo> threatreVos=new ArrayList<>();
        threatreVos.add(new ThreatreVo(1,"福田区华强北茂业百货九楼","深圳博纳国际影城华强店",0.3776D));
        return new Result<List<ThreatreVo>>().ok(threatreVos);
    }
}